package com.lwc.common.exceotion;

import com.lwc.common.bean.ResultBean;
import com.lwc.common.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.naming.SizeLimitExceededException;


@RestControllerAdvice   //异常 导包
public class GlobalExceptionHander  extends BaseController {

    @ExceptionHandler(ValidateException.class)
    public ResultBean expection( @Validated ValidateException e){
        return fail("验证错误",e.getError());
    }

    @ExceptionHandler(SizeLimitExceededException.class)
    public ResultBean SizeLimitExceededException( @Validated SizeLimitExceededException e){
        return fail("文件大小超过指定大小");
    }

    /**
     * 统一处理业务业务异常
     * @param e
     * @return
     */
    @ExceptionHandler(BusinessexCeption.class)
    public ResultBean BusinessnException( @Validated BusinessexCeption e){
        return fail(e.getMessage());
    }

}
